package Eyjafjalla.card.skill;

import Eyjafjalla.action.GainCloudEnergyAction;
import Eyjafjalla.action.GoodFriendAction;
import Eyjafjalla.action.MelodyAction;
import Eyjafjalla.card.AbstractEyjafjallaCard;
import Eyjafjalla.patch.MelodyPatch;
import Eyjafjalla.power.RedCloudPower;
import Eyjafjalla.power.WhiteCloudPower;
import Eyjafjalla.subscriber.MelodySubscriber;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.common.DamageRandomEnemyAction;
import com.megacrit.cardcrawl.actions.common.DrawCardAction;
import com.megacrit.cardcrawl.actions.common.HealAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.DamageInfo;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;

import java.util.ArrayList;

public class GoldAndRoses_Eyjafjalla extends AbstractEyjafjallaCard implements MelodySubscriber {
    public static final String ID = "GoldAndRoses_Eyjafjalla";
    private static final CardStrings cardStrings;

    public GoldAndRoses_Eyjafjalla(){
        super(ID, cardStrings.NAME,0,cardStrings.DESCRIPTION,CardType.SKILL,CardRarity.RARE,CardTarget.NONE);
        setFireDescription(cardStrings.EXTENDED_DESCRIPTION[0]);
        this.baseMagicNumber = 4;
        this.magicNumber = 4;
        this.exhaust = true;
    }

    @Override
    public AbstractCard makeCopy() {
        return new GoldAndRoses_Eyjafjalla();
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        addToBot(new MelodyAction(getSingle()));
    }

    public MelodyPatch.MelodySingle getSingle(){
        ArrayList<MelodyPatch.MelodyNote> notes = new ArrayList<>();
        notes.add(new MelodyPatch.MelodyNote(this,0,2,cardStrings.EXTENDED_DESCRIPTION[1]));
        notes.add(new MelodyPatch.MelodyNote(this,1,1,cardStrings.EXTENDED_DESCRIPTION[1]));
        notes.add(new MelodyPatch.MelodyNote(this,2,1,cardStrings.EXTENDED_DESCRIPTION[1]));
        notes.add(new MelodyPatch.MelodyNote(this,3,2,cardStrings.EXTENDED_DESCRIPTION[1]));
        notes.add(new MelodyPatch.MelodyNote(this,4,3,cardStrings.EXTENDED_DESCRIPTION[1]));

        MelodyPatch.MelodyNote finalNote = isFire()?new MelodyPatch.MelodyNote(this,-1,4,upgraded?cardStrings.EXTENDED_DESCRIPTION[3]:cardStrings.EXTENDED_DESCRIPTION[2]):null;
        MelodyPatch.MelodySingle single = new MelodyPatch.MelodySingle(this.name,notes,finalNote);
        return single;
    }

    @Override
    public ArrayList<AbstractGameAction> getNoteActions(boolean isFinal,int specialAmount) {
        ArrayList<AbstractGameAction> actions = new ArrayList<>();
        if(isFinal){
            actions.add(new HealAction(AbstractDungeon.player,AbstractDungeon.player,specialAmount));
        }
        else {
            for(AbstractMonster m:AbstractDungeon.getMonsters().monsters){
                if(!m.isDeadOrEscaped()){
                    actions.add(new ApplyPowerAction(m,AbstractDungeon.player,new WhiteCloudPower(m,1),1));
                }
            }
        }

        return actions;
    }

    @Override
    public int initializeSpecialAmount(boolean isFinal) {
        return this.magicNumber;
    }

    @Override
    public void upgrade() {
        if(!this.upgraded){
            upgradeName();
            upgradeMagicNumber(2);
        }
    }

    static {
        cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    }
}


